const {contextBridge, ipcRenderer} = require('electron')
const fs = require('fs')
contextBridge.exposeInMainWorld('versions', { // 桥接 会把主进程的一部分内容暴露给渲染进程中使用
    node: process.versions.node, // 预加载会绑定到window上
    chrome: process.versions.chrome
})
contextBridge.exposeInMainWorld('electron', {
    setTitle: (title) => {ipcRenderer.send('set-title', title)},
    writeFile: (content) => ipcRenderer.invoke('write-file', content),
    onUpateCounter: (callback)=> ipcRenderer.on('update-counter', (_event,value)=>callback(value)), // 传一个回调函数
    readFile: fs.promises.readFile
})